package com.itzxx.huazhun.ui.collection.readall

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.util.TimeUtils
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.itzxx.huazhun.data.model.ProbeStateInfo
import com.itzxx.huazhun.data.model.ProbeTestingInfo
import com.itzxx.huazhun.databinding.ItemRecordBinding
import com.itzxx.huazhun.data.model.RecordBean
import com.itzxx.huazhun.data.model.RecordChildBean
import com.itzxx.huazhun.databinding.ItemReadCollectionAllDataBinding
import com.itzxx.huazhun.databinding.ItemReadCollectionDataBinding
import com.itzxx.huazhun.databinding.ItemTestingNewBuildProbeBinding
import com.itzxx.library_base_ktx.ext.util.toDateStr

/**
 * Desc:
 *
 * Author: zhangxiaoxiao
 * Date: 2024/7/4 10:42
 * Updater:
 * Update Time:
 * Update Comments:
 */
class ReadCollectionAllDataAdapter : BaseQuickAdapter<ProbeTestingInfo, ReadCollectionAllDataAdapter.VH>() {

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: ItemReadCollectionAllDataBinding= ItemReadCollectionAllDataBinding.inflate(LayoutInflater.from(parent.context), parent, false),
    ) : RecyclerView.ViewHolder(binding.root)

    var checkMap = mutableMapOf<String,String>()

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: ProbeTestingInfo?) {
        item?.run {
            holder.binding.tvIndex.text = (position+1).toString()
            holder.binding.time.text = "${ recordStartTime}000".toLong().toDateStr("yyyy-MM-dd HH:mm")
            holder.binding.ckCheck.setOnCheckedChangeListener { compoundButton, b ->
                if (b){
                    checkMap[recordStartTime]  = recordStartTime
                }else{
                    checkMap.remove(recordStartTime)
                }
            }
            holder.binding.ckCheck.isChecked = checkMap.containsKey(recordStartTime)
        }

    }
}